<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            let arr = [1, 2, 3];

            arr.forEach((item, index, arr) => {
                console.log(item, index, arr);
            });
            // arr.forEach(arr);
            Array.prototype.myForEach = function (callback) {
                if (typeof callback !== 'function') {
                    throw new Error('参数必须是一个函数');
                }
                for (let i = 0; i < this.length; i++) {
                    callback(this[i], i, this);
                }
            };
            arr.myForEach(function (item, index, arr) {
                console.log(item, index, arr);
            });
        </script>
    </body>
</html>
